/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.portlet.bean.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import com.genia.toolbox.web.portlet.bean.Portlet;
import com.genia.toolbox.web.portlet.util.TrimUtils;

/**
 * A base implementation of <code>Portlet</code>.
 */
public abstract class AbstractPortlet
    implements Portlet
{

  /**
   * Indicates whether some other object is "equal to" this one.
   * 
   * @param obj
   *          the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the obj argument;
   *         <code>false</code> otherwise.
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(final Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() == obj.getClass()) {
      final Portlet oPortlet = (Portlet) obj;
      if (!ObjectUtils.nullSafeEquals(getIdentifier(), oPortlet.getIdentifier())) {
        return false;
      }
      if (!ObjectUtils.nullSafeEquals(getDescriptionName(), oPortlet.getDescriptionName())) {
        return false;
      }
      return ObjectUtils.nullSafeEquals(getAttributes(), oPortlet.getAttributes());
    }
    return false;
  }



  /**
   * Returns a hash code value for the object. This method is supported for the
   * benefit of hashtables such as those provided by
   * <code>java.util.Hashtable</code>.
   * 
   * @return a hash code value for this object.
   * @see java.lang.Object#hashCode()
   */
  @Override
  public abstract int hashCode();

  /**
   * the id of the current implementation of the portlet.
   */
  private String identifier;

  /**
   * the attributes of the portlet.
   */
  private Map<String, String> attributes = new HashMap<String, String>();

  /**
   * the name of the description of the portlet.
   */
  private String descriptionName = null;



  /**
   * getter for the identifier property.
   * 
   * @return the identifier
   */
  public String getIdentifier()
  {
    return identifier;
  }



  /**
   * setter for the identifier property.
   * 
   * @param identifier
   *          the identifier to set
   */
  public void setIdentifier(final String identifier)
  {
    this.identifier = identifier;
  }



  /**
   * getter for the attributes property.
   * 
   * @return the attributes
   */
  public Map<String, String> getAttributes()
  {
    return attributes;
  }



  /**
   * setter for the attributes property.
   * 
   * @param attributes
   *          the attributes to set
   */
  public void setAttributes(final Map<String, String> attributes)
  {
    this.attributes = TrimUtils.trimMap(attributes);
  }



  /**
   * getter for the descriptionName property.
   * 
   * @return the descriptionName
   */
  public String getDescriptionName()
  {
    return descriptionName;
  }



  /**
   * setter for the descriptionName property.
   * 
   * @param descriptionName
   *          the descriptionName to set
   */
  public void setDescriptionName(final String descriptionName)
  {
    this.descriptionName = StringUtils.trimWhitespace(descriptionName);
  }

}
